package info.marlan.sim;

import info.marlan.sim.util.DBHelper.Question;

import java.io.Serializable;
import java.util.List;

public class TestState implements Serializable {

	private static final long serialVersionUID = -234568631515077385L;
	public String name;
	public List<Question> questions;
	protected int question;
    protected boolean freeze;
    protected long counterTime = 0;
    protected long runtime = 15 * 60 * 1000; 
	private int correctAnswers = 0;
	private int possiblePoints = 0;
	private int points = 0;
	private boolean isCalculated;
	public boolean isSaved;
	private int[] stats;
	
	private void calcPoints(){
		if(isCalculated){
			return;
		}
		for(Question q:questions){
			possiblePoints+=q.severity;
			if(q.answeredCorrect()){
				correctAnswers++;
				points+=q.severity;
			}
		}
		if(freeze){
			isCalculated = true;
		}
	}
	public void setStats(int[] stats){
		this.stats = stats;
	}
	public int getStat(int position){
		if(stats==null || stats.length < (position-1)){
			return 0;
		}	
		return stats[position];
	}

	public int getCorrectAnswers() {
		calcPoints();
		return correctAnswers;
	}

	public int getPossiblePoints() {
		calcPoints();
		return possiblePoints;
	}

	public int getPoints() {
		calcPoints();
		return points;
	}
    
    
}
